package com.study.lilhan.niuke.demo.linkPointer;

import com.study.lilhan.niuke.demo.bean.ListNode;

/**
 * @Author: lihan
 * @Date : 2022/1/4- 01
 * @DESCRIPTION: 翻转单链表
 * @version: 1.0
 */
public class My78 {
    public static void main(String[] args) {
        ListNode node4 = new ListNode();
        node4.val = 4;
        ListNode node3 = new ListNode(3,node4);
        ListNode node2 = new ListNode(2,node3);
        ListNode node1 = new ListNode(1,node2);
        ListNode node = ReverseList(node1);
        System.out.println("运行结束");

    }

    public static  ListNode ReverseList(ListNode head) {
        if(head == null){
            return  null;
        }
        ListNode newHead = head;
        ListNode curNode = head.next;
        newHead.next = null;
        while (curNode != null){
            ListNode nextNode = curNode.next;
            curNode.next = newHead;
            newHead = curNode;
            curNode = nextNode;
        }

        return  newHead;
    }
}
